package com.zego.wawaji.ui.bean.wawa;

import android.os.Parcel;
import android.os.Parcelable;

import com.zego.wawaji.base.data.BaseData;

import org.json.JSONObject;

/**
 * 获取我的娃娃相关
 * Created by Su on 2017/12/1.
 */
public class MyWawa extends BaseData implements Parcelable {
    private long id;
    private int status;       // 状态 -1：未发货 1：用户请求发货 2：准备发货 3：已发货 4：已签收 5：用户已确认 6：已兑换为娃娃积分
    private long transPortID; // 自己服务器物流id
    private int wwTypeId;    // 娃娃类型id
    private String createTime;
    private long callbackTime; // 单位：s

    // ===== 内部娃娃分组使用字段，不需要解析 =============
    private int groupNum;               // 每组数量
    private boolean isNewGroup;         // 是否是新组
    private int costGold;               // 花费运费
    private boolean isLast;             // 是否是最后一条数据

    // ====== 发货是否选中 ===========
    private boolean isChoose = false;

    @Override
    public void parseJson(String jsonStr) {
        JSONObject jsonObject = getJsonObject(jsonStr);

        this.setId(jsonObject.optLong("Id"));
        this.setStatus(jsonObject.optInt("Status"));
        this.setTransPortID(jsonObject.optLong("Tid"));
        this.setWwTypeId(jsonObject.optInt("WwTypeId"));
        this.setCreateTime(jsonObject.optString("CreateTime"));
        this.setCallbackTime(jsonObject.optLong("CallbackTime"));
    }

    public boolean isChoose() {
        return isChoose;
    }

    public void setChoose(boolean choose) {
        isChoose = choose;
    }

    public int getCostGold() {
        return costGold;
    }

    public void setCostGold(int costGold) {
        this.costGold = costGold;
    }

    public boolean isNewGroup() {
        return isNewGroup;
    }

    public void setNewGroup(boolean newGroup) {
        isNewGroup = newGroup;
    }

    public int getGroupNum() {
        return groupNum;
    }

    public void setGroupNum(int groupNum) {
        this.groupNum = groupNum;
    }

    public long getCallbackTime() {
        return callbackTime;
    }

    public void setCallbackTime(long callbackTime) {
        this.callbackTime = callbackTime;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public long getTransPortID() {
        return transPortID;
    }

    public void setTransPortID(long transPortID) {
        this.transPortID = transPortID;
    }

    public int getWwTypeId() {
        return wwTypeId;
    }

    public void setWwTypeId(int wwTypeId) {
        this.wwTypeId = wwTypeId;
    }

    public MyWawa() {
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(this.id);
        dest.writeInt(this.status);
        dest.writeLong(this.transPortID);
        dest.writeInt(this.wwTypeId);
        dest.writeString(this.createTime);
        dest.writeLong(this.callbackTime);
        dest.writeInt(this.groupNum);
        dest.writeByte(this.isNewGroup ? (byte) 1 : (byte) 0);
        dest.writeInt(this.costGold);
        dest.writeByte(this.isLast ? (byte) 1 : (byte) 0);
        dest.writeByte(this.isChoose ? (byte) 1 : (byte) 0);
    }

    protected MyWawa(Parcel in) {
        this.id = in.readLong();
        this.status = in.readInt();
        this.transPortID = in.readLong();
        this.wwTypeId = in.readInt();
        this.createTime = in.readString();
        this.callbackTime = in.readLong();
        this.groupNum = in.readInt();
        this.isNewGroup = in.readByte() != 0;
        this.costGold = in.readInt();
        this.isLast = in.readByte() != 0;
        this.isChoose = in.readByte() != 0;
    }

    public static final Creator<MyWawa> CREATOR = new Creator<MyWawa>() {
        @Override
        public MyWawa createFromParcel(Parcel source) {
            return new MyWawa(source);
        }

        @Override
        public MyWawa[] newArray(int size) {
            return new MyWawa[size];
        }
    };
}
